package com.example.experiment_4;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText edAccount;
    private EditText edPassword;
    private Button btnRegister;
    private Button btnLogin;
    String account;     // 账号
    String password;    // 密码

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();

        btnRegister.setOnClickListener(this);
        btnLogin.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();

        if (id == R.id.btn_register) {
            getTextFromEditText();
            // 将account与password存储至xml文件中(注册)
            SPSaveLogin.saveUserInfo(account, password, this);
        } else if (id == R.id.btn_login) {
            getTextFromEditText();
            // 登录
            SPSaveLogin.login(account, password, this);
        }
    }

    private void getTextFromEditText() {
        account = edAccount.getText().toString();
        password = edPassword.getText().toString();
    }

    private void initView() {
        edAccount = findViewById(R.id.ed_account);
        edPassword = findViewById(R.id.ed_password);
        btnRegister = findViewById(R.id.btn_register);
        btnLogin = findViewById(R.id.btn_login);
    }

}